<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            let arr = [1, 2, 3, 4, 5];
            arr.reverse();
            console.log(arr); // [5, 4, 3, 2, 1]

            console.log(Array.prototype);

            Array.prototype.myReverse = function () {
                let len = this.length - 1;
                for (let i = 0; i < Math.floor(this.length / 2); i++) {
                    // 交换这两个元素位置
                    let temp = arr[i];
                    arr[i] = arr[len];
                    arr[len--] = temp;
                }
                return this;
            };
            arr.myReverse();
            console.log(arr); // [5, 4, 3, 2, 1]
        </script>
    </body>
</html>
